package com.czk.workqueue.consumer;

import com.czk.utils.RabbitmqUtils;
import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/**
 * 第三个 消费者的映入
 *
 * @Author:ChenZhangKun
 * @Date: 2021/8/11 15:45
 */
public class ThirdConsumer {
    public static void main(String[] args) throws IOException, TimeoutException, InterruptedException {
        // 拿到连接
        Connection czkConnection = RabbitmqUtils.getCzkConnection();
        // 拿到通道
        Channel channel = czkConnection.createChannel();
        DeliverCallback deliverCallback = (String var1, Delivery var2) -> {
            String message = new String(var2.getBody());
            System.out.println(message);
        };
        CancelCallback cancelCallback = (String var1) -> {
            System.out.println("消息消费被中断");
        };
        TimeUnit.SECONDS.sleep(1);
        channel.basicConsume("work", true, deliverCallback, cancelCallback);
    }
}
